<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="部门名称" prop="industryTitle"
                :rules="[
                 ]">
              <el-input v-model="inputForm.industryTitle" placeholder="请填写部门名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="员工姓名" prop="staffName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.staffName" placeholder="请填写员工姓名"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程编号" prop="jobNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.jobNumber" placeholder="请填写工程编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程大项" prop="singleProject"
                :rules="[
                 ]">
              <el-input v-model="inputForm.singleProject" placeholder="请填写工程大项"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="单项名称" prop="singleName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.singleName" placeholder="请填写单项名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="本工程合同金额" prop="contractAmount"
                :rules="[
                 ]">
              <el-input v-model="inputForm.contractAmount" placeholder="请填写本工程合同金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程状态" prop="projectStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.projectStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('project_status')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="归档编号" prop="fileNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.fileNumber" placeholder="请填写归档编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="预计收入" prop="anticipatedIncome"
                :rules="[
                 ]">
              <el-input v-model="inputForm.anticipatedIncome" placeholder="请填写预计收入"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="审定收入合计" prop="totalAuditIncome"
                :rules="[
                 ]">
              <el-input v-model="inputForm.totalAuditIncome" placeholder="请填写审定收入合计"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="审定日期" prop="approvalDate"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.approvalDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          industryTitle: '',
          staffName: '',
          jobNumber: '',
          singleProject: '',
          singleName: '',
          contractAmount: '',
          projectStatus: '',
          fileNumber: '',
          anticipatedIncome: '',
          totalAuditIncome: '',
          approvalDate: '',
          remarks: ''
        }
      }
    },
    components: {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建承揽合同工程信息表`
        } else if (method === 'edit') {
          this.title = '修改承揽合同工程信息表'
        } else if (method === 'view') {
          this.title = '查看承揽合同工程信息表'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/epc/contracthireofwork/contractHireofWorkInformation/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.contractHireofWorkInformation)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/epc/contracthireofwork/contractHireofWorkInformation/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>